#ATM机的存取款功能
#1、先登录
#   根据用户登录
#2、菜单界面
#   1、取款
#      用户的账户金额就减少了500
#   2、存款
#      用户的账户金额就增加了500块
#   3、查询
#      用户的账户金额显示
def login(username,passwd):
    while True:
        if username in users_pw and passwd == users_pw[username]:
            print(f"恭喜{username}已登陆成功！")
            return True
        else:
            print("您的账号或密码有误，请重新输入!")
            break
# 取钱功能
def withdrew():
    global have_money
    need_money = int(input("请输入您要取的金额："))
    if need_money < have_money:
        print("您已成功取出：",need_money)
        have_money -= need_money
        return have_money
    else:
        print("您的存款不足，请重新输入！")

# 存钱功能
def save_money():
    global have_money
    # have_money = 1000
    cun_money = int(input("请输入您存入的数目："))
    print(f"您已成功存入{cun_money}")
    have_money += cun_money
    return have_money

# 查看功能
def view_money():
    global have_money
    print(f"您现有存款{have_money}")

users_pw = {"root":"123456","chaochao":"654321"}
have_money = 1000
username = input("请输入您用户名：")
password = input("请输入登录密码：")
if login(username,password):
    while True:
        print("取款请输入1\n存款请输入2\n查询余额请按3(退出请输入exit)")
        k = input("请输入您需要的服务：")
        if k == "exit":
            print("您已推出超超银行，期待您下次送钱！")
            break
        elif k == "1":
            withdrew()
        elif k == "2":
            save_money()
        elif k == "3":
            view_money()
        else:
            print("您的输入有误请重新输入")

